package com.wl.network.demo05;

import java.net.DatagramPacket;
import java.net.DatagramSocket;

public class UDPReceive {
    public static void main(String[] args) {
        try {
            DatagramSocket datagramSocket = new DatagramSocket(9090);
            while (true){
                byte[] container = new byte[1024];
                DatagramPacket datagramPacket = new DatagramPacket(container,0,container.length);
                datagramSocket.receive(datagramPacket);
                //断开连接
                byte[] data = datagramPacket.getData();
                String datas = new String(data, 0, datagramPacket.getLength());
                System.out.println(datas);
                if (datas.equals("0")){
                    break;
                }
            }
            datagramSocket.close();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
